import {
	defineStore
} from 'pinia';
import {
	api as Api,
	tools
} from '../api/api.js'


const empty = {
	tbUser: {},
	tbUserInfo: {},
	tbRole: {},
	exInfo: {},
	logo: ''
}
export const store = defineStore('user', {
	state() {
		return {
			user: empty,
			isLogin: false,
		}
	},
	actions: {
		update(cb) {
			let instance = this;
			Api.get('/auth', {}, (data) => {
				if (data.success) {
					instance.isLogin = true;
					instance.user = data.data;
					instance.user.logo = tools.userlogo(data.data.tbUser.uid)
				} else {
					instance.isLogin = false;
					instance.user = empty;
				}
				cb?.(data.success);
			});
		},
	},
});

export default store;